<template>
    <div ref="loginWrap" class="login-wrap">
        <div class="login-box">
            <div class="login-logo">
                <img src="../../assets/login-logo.png"/>
            </div>
            <!-- 登录 -->
            <div class="login-box-wrap" >
                <div class="login-left">
                    <h2>鲜檬摄影门店登录</h2>
                    <div class="block"></div>
                    <p>留存记忆，传递情感</p>
                </div>
                <div class="login-right">
                    <h2>登入</h2>
                    <div class="box-wrap">
                        <div>
                          <el-form :model="loginForm" :rules="loginRules" ref="loginForm" class="demo-ruleForm">
                            <el-form-item  prop="userLogin">
                                <el-input size="small" placeholder="请输入用户名" v-model="loginForm.userLogin">
                                  <template style="width:30px" slot="prepend"><i class="el-icon-user-solid"></i></template>
                                </el-input>
                            </el-form-item>

                            <el-form-item  prop="password">
                                <el-input size="small" placeholder="请输入密码" type="password" v-model="loginForm.password">
                                  <template style="width:30px" slot="prepend"><i class="el-icon-key"></i></template>
                                </el-input>
                            </el-form-item>
                            <div class="captcha">
                              <el-form-item class="captcha-input"  prop="code">
                                  <el-input size="small" placeholder="请输入验证码"  v-model="loginForm.code">
                                  </el-input>
                              </el-form-item>

                              <div class="captcha-img" @click="getCaptchaCode">
                                  <img width="100%" height="100%" :src="captchaImg" alt="">
                              </div>
                            </div>
                          </el-form>
                        </div>
                       
                        <button class="login-submit" @click="login">登录</button>
                        <div class="login-check-box">
                        </div>
                    </div>
                    <!-- <p class="contact">若遗失或者遗忘登入密码，请联系系统管理员:800800888</p> -->
                </div>
            </div>
            
        </div>
        <div class="login-footer">Copyright © 2018-2021 广东虎彩影像有限公司 <span class="login_ICP_link" >粤ICP备15104595号</span></div>
    </div>
</template>

<script>
import {Cookie } from '../../utils/index'
export default {
    components: {
    },
    data() {
        return {
            // 验证码图片
            captchaImg:'',
          loginForm:{
            userLogin:'',
            password:'',
            code:'',
        //   登录验证随机码
            loginFlagCode :''
          },
          loginRules:{
            userLogin:[
              { required: true, message: '请输入用户名', trigger: 'blur' },
            ],
            password:[
              { required: true, message: '请输入密码', trigger: 'blur' },
            ],
            code:[
              { required: true, message: '请输入验证码', trigger: 'blur' },
            ]
          },
        }
    },
    methods: {
       formmat(list, newarr){
        list.forEach(ele => {
            if(ele.module_level == 1){
                ele.children = []
                newarr.push(ele)
            }else{
                this.getChildren(newarr, ele)
            }
        });
        return newarr
       },
       getChildren(list, obj){
           for (let i = 0; i < list.length; i++) {
                if(list[i].module_id == obj.parent_module_id){
                    list[i].children.push(obj)
                }
           }
       },
       getBtn(list, btn){
           list.forEach(ele => {
               if(ele.module_id == btn.module_id){
                   if((ele.btnList || []).length==0){
                       ele.btnList = []
                       ele.btnList.push(btn)
                   }else{
                       ele.btnList.push(btn)
                   }
               }
               if(ele.children && ele.children.length > 0){
                   this.getBtn(ele.children, btn)
               }
           });
       },
      login(){
          let _this = this
          let menus = []
        this.$refs.loginForm.validate((valid) => {
            let data = this.loginForm
          if (valid) {
              this.ajax({
                  url: '/api/OriginOrderManaApi/CheckLogin',
              data,
              success: res => {
                  if(res.code == 0){
                    menus = this.formmat(res.data.modules, [])
                    res.data.permissions.forEach(element => {
                        this.getBtn(menus, element)
                    });
                    let { BranchName,StoreId,StoreName,UserId,UserLogin,BranchId } = res.data
                    let userinfo ={BranchName,StoreId,StoreName,UserId,UserLogin,BranchId }
                    this.$store.dispatch('setMenusAndUserInfo',menus, userinfo)
                    Cookie.set({
                        key:'STORE_MENUS',
                        value: JSON.stringify(menus)
                    })
                    Cookie.set({
                        key:'STORE_INFO',
                        value: JSON.stringify(userinfo)
                    })
                    this.loadPage('83')

                  }
                  if(res.code == 1){
                      this.$message(`${res.msg}`);
                  }
                this.getCaptchaCode()
              }
            })
          } else {
            return false;
          }
        });
      },
      changeRoute(){
          console.log('change')
      },
      getCaptchaCode(){
          // 获取随机码
          this.loginForm.loginFlagCode = this.getLoginCode()
          this.ajax({
              url:`/api/OriginOrderManaApi/VCode?loginFlagCode=${this.loginForm.loginFlagCode}`,
              type:'get',
              responseType: 'blob',
              success:res=>{
                  console.log(res)
                  this.captchaImg = window.URL.createObjectURL(res)
              }
          })
      },
    },
    created () {
        this.getCaptchaCode()
    },
    mounted () {
     
    },
    beforeDestroy() {
        
    }
}
</script>

<style scoped lang='scss'>
.captcha{
  width: 100%;
  display: flex;
  justify-content: space-between;
  .captcha-input{
    width: 48%;
  }
  .captcha-img{
    width: 48%;
    height: 32px;
    margin-top: 5px;
  }
}


    .auto-login-check .el-checkbox__inner{
        border: 1px solid #999;
    }
    .auto-login-check .el-checkbox__input.is-checked .el-checkbox__inner, 
    .auto-login-check .el-checkbox__input.is-indeterminate .el-checkbox__inner {
        background-color: #1A1A1A;
        border-color: #1A1A1A;
    }
    .auto-login-check .el-checkbox__label {
        font-size: 12px;
        color: #666;
        padding-left: 5px;
    }
    .auto-login-check .el-checkbox__input.is-checked+.el-checkbox__label {
        color: #666;
    }
    .auto-login-check .el-checkbox__inner::after {
        border-color:  #FFE127;
    }
    .password-step .el-step__title.is-process,.password-step .el-step__title.is-finish {
        font-weight: normal;
        color: #1A1A1A;
    }
    .password-step .el-step__title {
        font-size: 14px;
        line-height: 32px;
        color: #999;
    }
    .password-step .el-step__icon-inner {
        color: #999;
        font-size: 20px;
    }
    .password-step .el-step__icon {
        width: 48px;
        height: 48px;
        background: #E5E5E5;
        border: none;
    }
    .password-step .el-step__head.is-finish {
        color: #FFE127;
        border-color: #FFE127;
    }
    .password-step .el-step__icon.is-text {
        border: none;
    }
    .password-step .el-step__head.is-process .el-step__icon.is-text, 
    .password-step .el-step__head.is-finish .el-step__icon.is-text{
        background: #FFE127;
        color: #1a1a1a;
        border: none;
    }
    .password-step .el-step__head.is-process .el-step__icon-inner, 
    .password-step .el-step__head.is-finish .el-step__icon-inner{
        color: #1a1a1a;
    }
    .password-step .el-step.is-horizontal .el-step__line {
        top: 25px;
    }
    .password-step .el-step__line {
        color: #E5E5E5;
        background-color: #E5E5E5;
    }
    .password-step .el-step__head.is-finish .el-step__line, 
    .password-step .el-step__head.is-finish .el-step__line-inner {
        color: #FFE127;
        background-color: #FFE127;
    }
</style>


<style lang="scss" scoped>
    
    .pc-hide {
        display: none;
    }
    .login-wrap {
        width: 100%;
        // height: auto;
        min-height: 100%;
        background: url('../../assets/bg.png') no-repeat;
        background-size: cover;
        position: relative;
        // display: flex;
        // flex-wrap: wrap;
        // align-items: center;
        .login-box {
            // width: 660px;
            height: auto;
            // min-height: 757px;
            margin: 0 auto;
            overflow: hidden;
            
            .login-logo {
                width: 300px;
                margin-bottom: 40px;
                margin-left: auto;
                margin-right: auto;
                img {
                    width: 300px;
                    display: block;
                }
            }
            .login-box-wrap {
                // width: 660px;
                // height: 412px;
                margin-bottom: 40px;
                background:#fff;
                box-shadow:0px 5px 23px 0px rgba(0,0,0,0.6);
                border-radius:9px;
                overflow: hidden;
                display: flex;
                justify-content: space-between;
                h2 {
                    font-size: 24px;
                    font-weight: 600;
                    line-height: 31px;
                    margin-top: 53px;
                }
                .login-left {
                    // width: 280px;
                    height: 100%;
                    background-color: #FFE127;
                    background-image: url('../../assets/loginpattern.png');
                    background-repeat: no-repeat;
                    // background-position: 8px bottom;
                    // background-size: 266px 67px;
                    padding-left: 30px;
                    color: #1A1A1A;
                    overflow: hidden;
                    .block {
                        width: 80px;
                        height: 6px;
                        background: #1A1A1A;
                        margin-top: 40px;
                    }
                    p {
                        margin-top: 27px;
                        font-size: 14px;
                        line-height: 19px;
                    }
                }
                .login-right {
                    // width: 380px;
                    h2 {
                        width: 100%;
                        text-align: center;
                    }
                    .box-wrap {
                        width: 320px;
                        margin: 0 auto;
                        .login-check-box {
                            width: 320px;
                            margin-top: 10px;
                            color: #666;
                            font-size: 12px;
                            .forget {
                                float: right;
                                cursor: pointer;
                            }
                        }
                        p {
                            width: 320px;
                            text-align: center;
                            margin-top: 36px;
                            font-size: 12px;
                            color: #999;
                        }
                        
                    }
                    p.contact {
                        width: 100%;
                        text-align: center;
                        margin-top: 36px;
                        font-size: 12px;
                        color: #999;
                    }
                }
                .login-item {
                    height: 34px;
                    line-height: 34px;
                    margin-top: 30px;
                    position: relative;
                    span.absolute {
                        display: flex;
                        width: 70px;
                        height: 34px;
                        position: absolute;
                        top: 0;
                        left: 0;
                        span {
                            display: inline-block;
                            height: 34px;
                            margin-right: 5px;
                        }
                        .icon {
                            width: 18px;
                            height: 34px;
                            font-size: 18px;
                        }
                    }
                    input {
                        width: 320px;
                        height: 33px;
                        padding-left: 70px;
                        outline: none;
                        font-size: 14px;
                        border-bottom: solid 1px #999;
                        &:focus {
                            border-color: #1A1A1A;
                        }
                        &.wrong {
                            border-color: #F9403A;
                        }
                    }
                    input::-webkit-input-placeholder {
                        /* placeholder颜色  */
                        color: #ccc;
                    }
                    input::-webkit-outer-spin-button,
                    input::-webkit-inner-spin-button {
                        -webkit-appearance: none;
                    }
                    input[type="number"] {
                        -moz-appearance: textfield;
                    }
                    .error, .confirm {
                        width: 320px;
                        height: 30px;
                        position: absolute;
                        right: 0;
                        bottom: -24px;
                        line-height: 36px;
                        font-size: 12px;
                        color: #F9403A;
                        overflow: hidden;
                        text-align: right;
                        .error-wrap {
                            display: flex;
                            justify-content: flex-end;
                            i.emoji {
                                width: 22px;
                                height: 22px;
                                display: inline-block;
                                margin-top: 6px;
                                margin-right: 3px;
                                background: url('../../assets/emoji-thinking.png') no-repeat;
                                background-size: cover;
                            }
                            span {
                                display: block;
                                width: auto;
                                position: inherit;
                            }
                        }
                        img {
                            margin-right: 3px;
                            display: block;
                            margin-top: 8px;
                        }
                        span {
                            display: inline-block;
                            width: auto;
                            right: 0;
                        }
                    }
                    .confirm {
                        color: #666;
                        text-align: left;
                        b {
                            color: #FF8B2B;
                            font-weight: normal;
                        }
                    }
                }
                .login-submit {
                    width: 320px;
                    height: 40px;
                    font-size: 14px;
                    background: #1a1a1a;
                    color: #FFE127;
                    border-radius: 2px;
                    border: none;
                    margin-top: 40px;
                    transition: all .5s;
                    cursor: pointer;
                    &:hover {
                        background: #333;
                    }
                }
                &.forget-pwd {
                    display: block;
                    // height: 480px;
                    height: auto;
                }
                .forget-title {
                    width: 100%;
                    padding: 0 30px;
                    height: 50px;
                    line-height: 50px;
                    background: #FFE127;
                    display: flex;
                    justify-content: space-between;
                    span {
                        color: #1A1A1A;
                        font-size: 16px;
                        font-weight: 600;
                        vertical-align: middle;
                        &.return-back {
                            display: flex;
                        }
                        .icon {
                            width: 16px;
                            height: 50px;
                            vertical-align: middle;
                            margin-right: 4px;
                        }
                    }
                }
                .forget-password-wrap {
                    width: 100%;
                    padding: 30px 0 40px;
                }
                .step-wrap {
                    width: 660px;
                    height: 76px;
                    padding: 0 80px;
                }
                .forget-step-1, .forget-step-2, .forget-step-3, .forget-step-4 {
                    width: 320px;
                    margin: 50px auto 0;
                    .phone-dropdown {
                        span {
                            display: inline-block;
                            width: auto;
                            position: inherit;
                            color: #1A1A1A;
                        }
                        .el-icon--right {
                            margin-left: 0;
                        }
                    }
                    .code-item {
                        display: flex;
                        height: 40px;
                    }
                    input {
                        width: 320px;
                        padding-left: 80px;
                        &.code {
                            width: 200px;
                            padding-left: 0;
                            margin-top: 7px;
                        }
                    }
                    .code-image {
                        width: 100px;
                        height: 40px;
                        display: inline-block;
                        margin-left: 20px;
                        position: relative;
                        button {
                            width: 100px;
                            height: 40px;
                            border: none;
                            border-radius: 4px;
                            background: #FFE127;
                            color: #1A1A1A;
                            font-size: 14px;
                            outline: none;
                            &.send:hover {
                                background: #FFCD27;
                            }
                            &.gray {
                                background: #E5E5E5;
                                color: #999;
                                &:hover {
                                    background: #E5E5E5;
                                    color: #999;
                                }
                            }
                        }
                        button.auth-text {
                            position: absolute;
                            top: 0;
                            left: 0;
                            background: #ccc;
                            color: #999;
                            cursor: not-allowed;
                        }
                    }
                    .login-submit {
                        width: 320px;
                    }
                    .error, .confirm {
                        width: 320px;
                    }
                }
                .forget-step-2 {
                    .btn-box {
                        width: 320px;
                        margin-top: 70px;
                        display: flex;
                        justify-content: space-between;
                        button {
                            width: 150px;
                            height: 40px;
                            outline: none;
                            border: none;
                            border-radius: 2px;
                            font-size: 14px;
                            transition: all .5s;
                            cursor: pointer;
                            &.back {
                                background: #fff;
                                border: solid 1px #999;
                                color: #666;
                                &:hover {
                                    border-color: #1A1A1A;
                                }
                            }
                            &.on {
                                background: #1A1A1A;
                                color: #FFE127;
                                &:hover {
                                    background: #333;
                                }
                            }
                        }
                    }
                    .login-item input.code {
                        width: 200px;
                    }
                    .code-image {
                        position: relative;
                        button {
                            width: 100px;
                        }
                        .auth-text {
                            position: absolute;
                            top: 0;
                            left: 0;
                            background: #ccc;
                            color: #999;
                            cursor: not-allowed;
                        }
                    }
                    .error.msg-code {
                        bottom: -50px;
                        text-align: left;
                    }
                }
                .forget-step-3 {
                    .login-item {
                        span {
                            width: 75px;
                        }
                        input {
                            padding-left: 100px;
                        }
                        .error {
                            span {
                                width: 320px;
                            }
                        }
                        span.right {
                            position: absolute;
                            top: 0;
                            right: 0;
                            left: auto;
                            width: 18px;
                            height: 34px;
                        }
                    }
                }
                .forget-step-4 {
                    .success-box {
                        width: 320px;
                        margin-top: 50px;
                        text-align: center;
                        .success-icon {
                            width: 340px;
                            span {
                                display: inline-block;
                                width: 60px;
                                height: 60px;
                                background: #1A1A1A;
                                border-radius: 50%;
                                line-height: 60px;
                                .icon {
                                    width: 32px;
                                    height: 32px;
                                    font-size: 32px;
                                    vertical-align: middle;
                                }
                            }
                        }
                        p {
                            margin-top: 24px;
                            font-size: 16px;
                        }
                        .number {
                            color: #999;
                            margin-top: 14px;
                        }
                    }
                }
            }
        }
        .login-footer {
                // margin-top: 118px;
                // margin-bottom: 30px;
                // width: 660px;
                // text-align: center;
                // position: absolute;
                // left: 27%;
                // bottom: 40px;
                color: #999;
                width: inherit !important;
                text-align: center;
                .login_ICP_link{
                    cursor: pointer;
                }
                .login_ICP_link:hover{
                    text-decoration: underline;
                }
                // padding-bottom: 40px;
            }
    }
    @media screen and (max-width: 1439px){
        .login-box,.login-wrap .login-footer {width: 580px;}
        .login-wrap .login-footer {left: 28%;}
        .login-box-wrap {width: 580px;height:340px;}
        .login-logo {margin-top: 100px;}
        .login-left {width: 212px;background-size: 203px 53px;background-position: 9px bottom;}
        .login-wrap .login-box .login-box-wrap .login-left {padding-left:20px;}
        .login-wrap .login-box .login-box-wrap h2 {font-size: 18px;margin-top: 30px;}
        .login-wrap .login-box .login-box-wrap .login-left .block {width:40px;height:4px;margin-top:23px;}
        .login-wrap .login-box .login-box-wrap .login-item:nth-child(1) {margin-top: 20px;}
        .login-wrap .login-box .login-box-wrap .login-submit {margin-top: 30px;}
        .login-wrap .login-box .login-box-wrap .login-right .box-wrap .login-check-box {margin-top: 13px;}
        .login-wrap .login-box .login-box-wrap .login-right p.contact {margin-top: 30px;}
        .login-wrap .login-box .login-box-wrap .login-right .box-wrap,
        .login-wrap .login-box .login-box-wrap .login-item input,
        .login-wrap .login-box .login-box-wrap .login-submit,
        .login-wrap .login-box .login-box-wrap .login-right .box-wrap .login-check-box {width: 308px;}
        .login-right {width: 368px}
        .login-wrap .login-box .login-box-wrap .step-wrap {width: 580px;padding: 0 50px;}
    }
    @media screen and (min-width: 1440px){
        .login-box,.login-wrap .login-footer {width: 660px;}
        .login-box-wrap {width: 660px;height:412px;}
        .login-logo {margin-top: 100px;}
        .login-left {width: 280px;background-size: 264px 67px;background-position: 14px bottom;}
        .login-right {width: 380px}
    }
    // @media screen and (min-width: 1441px) and (max-width:1600px){
    //     .login-box {width: 720px;}
    //     .login-box-wrap {width: 720px;height:450px;}
    //     .login-logo {margin-top: 120px;}
    //     .login-left {width: 310px;background-size: 298px 76px;background-position: 11px bottom;}
    //     .login-right {width: 410px}
    // }
    @media screen and (min-width: 1601px) and (max-width: 1920px){
        .login-box,.login-wrap .login-footer {width: 860px;}
        .login-box-wrap {width: 860px;height:520px;}
        .login-logo {margin-top: 140px;}
        .login-left {width: 380px;background-size: 354px 89px;background-position: 19px bottom;}
        .login-right {width: 480px}
        .login-wrap .login-box .login-box-wrap .step-wrap {width: 860px;}
        .login-wrap .login-box .login-box-wrap .login-item:first-child {margin-top: 70px;}
        .login-wrap .login-box .login-box-wrap .login-right p.contact {margin-top: 80px;}
    }
</style>


